package com.jz.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.jz.dao.ModelDAO;
import com.jz.model.Model;

public class ModelDAOImpl extends HibernateDaoSupport implements ModelDAO {

	public void deleteModel(Model model) {
		getHibernateTemplate().delete(model);
	}

	public List<Model> getModels() {
		return getHibernateTemplate().find("from Model");
	}

	public void insertModel(Model model) {
		getHibernateTemplate().save(model);
	}

	public void updateModel(Model model) {
		getHibernateTemplate().update(model);
	}

	public Model getModelById(Integer modelId) {
		Query query=this.getSession().createQuery("from Model model where model.number=?");
		query.setInteger(0,modelId);
		List<Model> modelList = query.list();
		return modelList.size()>0 ? modelList.get(0) : null;
	}

}
